// 商品管理脚本
$(function() {
	/*$("#searchid").linkbutton({
				text : '查询',
				iconCls : 'icon-search'
			});
			*/
	$('#messagegrid').datagrid({
		title : '您所在的位置：论坛管理模块&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;版主管理',
		idField : 'id',
		width : 1000,
		height : 400,
		nowrap : false,
		striped : true,
		collapsible : false,
		url : '../tribuneMaster/tribuneMaster_searchTribuneMaster.shtml',
		frozenColumns : [[{
					field : 'ck',
					title : '选择',
					checkbox : true
				}]],
		columns : [[{
					title : '基本信息',
					colspan : 3
				}, {
					field : 'opt',
					title : '操作',
					width : 150,
					align : 'center',
					rowspan : 2,
					formatter : function(value, rec) {
						if (rec.id == undefined)
							return null;
						else
							return '<span onclick=ondelete("'
									+ rec.id + '")><font style="cursor:pointer;color:blue;">删除</font></span></span><hr/><select id=aud_'+rec.id +'><option value="1">审核通过</option><option value="2">审核不通过</option></select>&nbsp;&nbsp;&nbsp; <span onclick=onAutding("'
									+ rec.id + '")><font style="cursor:pointer;color:blue;">审核</font></span></span>';
					}
				}], [{
					field : 'userName',
					title : '申请人',
					mapping : 'userName',
					align : 'center',
					width : 100
				}, {
					field : 'applyTimeString',
					title : '申请时间',
					width : 150,
					mapping : 'applyTimeString',
					align : 'center' 
				},{
					field : 'auding',
					title : '状态',
					align:'center',
					width : 100,
					formatter : function(value, rec) {
					     if(value==0) {
						     return  "<font color='red'>未审核</font>";
					     }
					     if(value==1){
						 return "通过";
						 }
						 if(value==2)
						 {
						  return "不通过";
						 }
					}
					
				}
		]],
		pagination : true,
		rownumbers : true,
		queryParams : {
			startTime : '',
			endTime : ''
		},
		toolbar : [ {
					id : 'btnsave',
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						var records = $('#messagegrid').datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要删除的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定删除所选信息吗?")) {
						var url1 = "../tribuneMaster/tribuneMaster_deleteTribuneMaster.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids ,
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnadd',
					text : '同意申请',
					iconCls : 'icon-ok',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要标记的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定标记所选记录吗?")) {
						var url1 = "../tribuneMaster/tribuneMaster_audingTribuneMaster.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids + "&auding=1",
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnadd',
					text : '撤销申请',
					iconCls : 'icon-undo',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要撤销标记的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定撤销标记所选记录吗?")) {
						var url1 = "../tribuneMaster/tribuneMaster_audingTribuneMaster.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids + "&auding=2",
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnclose',
					text : '  &nbsp;关  闭',
					iconCls : 'icon-cancel',
					handler : function() {
						window.self.close();
					}
				}
				]
		}
	);
});

function onSearch() {
    //var category= $("#category").combobox("getValue");
	var queryParams = $('#messagegrid').datagrid("options").queryParams;
//	queryParams.startTime = $("#startTime").val();
//	queryParams.endTime = $("#endTime").val();
	//queryParams.category =category;
	$('#messagegrid').datagrid("reload");
}

function ondelete(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定删除此条记录吗?")) {
		var url1 = "../tribuneMaster/tribuneMaster_deleteTribuneMaster.shtml";
		$.ajax({
				url : url1,
				data : "idString=" + id,
				success : function(msg) {
					var obj = eval('(' + msg + ')');
					var result = obj[0]["message"];
					alert(result);
					$('#messagegrid').datagrid("reload");
				}
			});
	}
}
function onAutding(id) {
		if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定审核此条信息吗?")) {
        var autding=document.getElementById("aud_"+id).value;
		var url1 = "../tribuneMaster/tribuneMaster_audingTribuneMaster.shtml";
			$.ajax({
					url : url1,
					data : "idString=" + id+"&auding="+autding ,
					cache:false,
					success : function(msg) {
   					   var obj = eval('(' + msg + ')');
                       var result = obj[0]["message"];
                         if(!result){
                                     alert("审核失败");
                                     return;
		                     }
		                  alert("审核成功");
						$('#messagegrid').datagrid("reload");
					}
				});
	}
}
function onView(id) {
	if (id == "undefined") {
		alert("此条记录已被删除");
		return;
	} 
	window.open('../tribune/tribune_searchById.shtml?id='+id);
}
